const shop = require('../../../mixins/shop');
const app = getApp();
const options = {

  /**
   * 页面的初始数据
   */
  data: {
    aid: -1,
    addsinfo: {},
    goodslist: [],
    amount: 0,
    vipAmount: 0,
    discountsAmount: 0,
    user_remark: '',
    payPopup: false,
    payTitle: '支付成功',
    showCheckoutOrder: true,
  },
  onLoad: function (options) {
    this.getShopPliceOrderGoods();
  },
  onShow: function () {
    this.getAdds();
  },
  //提交订单
  checkoutOrder() {
    let that = this;
    if (that.data.addsinfo.name) {
      if (that.data.showCheckoutOrder) {
        wx.showLoading({
          title: '订单提交中',
        })
        that.setData({
          showCheckoutOrder: false
        })
        that.shopPliceOrder();
      }
    } else {
      wx.showToast({
        title: '暂未选择收货地址',
        icon: 'none',
      })
    }
  },
  toOrder() {
    this.setData({
      payPopup: false
    })
    wx.reLaunch({
      url: '/pages/shop/order/order',
    })
  },
  calculateFun() {
    let that = this;
    let goodslist = that.data.goodslist;
    let amount = 0.00;
    let vipAmount = 0.00;
    let discountsAmount = 0.00;
    for (let v of goodslist) {
      amount = amount + parseFloat(v.price * v.num);
      vipAmount = vipAmount + parseFloat(v.vip_price * v.num);
    }
    discountsAmount = amount.toFixed(2) - vipAmount.toFixed(2);
    amount = amount.toFixed(2);
    vipAmount = vipAmount.toFixed(2);
    discountsAmount = discountsAmount.toFixed(2);
    that.setData({
      amount: amount,
      vipAmount: vipAmount,
      discountsAmount: discountsAmount,
    })
  },
  bindTextAreaBlur(e) {
    this.setData({
      user_remark: e.detail.value
    })
  },
  getAdds(id) {
    if (id) {
      this.setData({
        aid: id
      })
    }
    this.getShopGetCheckAdds();
  },
  toAdds() {
    let that = this;
    let addsinfo = that.data.addsinfo;
    let id = that.data.aid;
    if (addsinfo) {
      id = addsinfo.id;
    }
    wx.navigateTo({
      url: '/pages/mine/address/address?id=' + id,
    })
  },
  onShareAppMessage: function () {},
}

shop(options)
Page(options)